function e(e, t, a) {
    return t in e ? Object.defineProperty(e, t, {
        value: a,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = a, e;
}

var t, a = require("../../../utils/function.js"), n = require("../../../api.js"), o = getApp(), s = require("../../../siteinfo.js");

Page({
    data: (t = {
        getPhoneAndYanZhengMa: !0,
        sendtxt: "获取验证码",
        phone: null
    }, e(t, "phone", ""), e(t, "verificationcode", ""), e(t, "sendtxt", "发送验证码"), e(t, "gettingCode", !0), 
    e(t, "successCallback", null), t),
    onLoad: function() {
        this.getImgCode();
    },
    getImgCode: function() {
        var e = this, t = s.siteroot;
        t = t.replace("/app/index.php", ""), o.request({
            url: n.user.getCatchaKey,
            method: "post",
            data: {},
            success: function(a) {
                e.data.imgCodeKey = a.data.key, e.setData({
                    showCode: t + "/index.php?s=api/user/getCaptcha&_acid=" + s.acid + "&time=" + new Date().getTime()
                });
            }
        });
    },
    phoneinput: function(e) {
        this.setData({
            phone: e.detail.value
        }), wx.setStorageSync("phonep", e.detail.value);
    },
    getPhoneNumber: function(e) {
        console.log(e);
    },
    phonecode: function(e) {
        this.setData({
            verificationcode: e.detail.value
        });
    },
    imgcodeinput: function(e) {
        this.setData({
            imgcode: e.detail.value
        });
    },
    sendcode: function() {
        var e = this;
        e.data.gettingCode && ("" != e.data.phone && /^1\d{10}$/.test(e.data.phone) ? (wx.showLoading({}), 
        o.request({
            url: n.user.check_phone,
            method: "post",
            data: {
                phone: e.data.phone
            },
            success: function(t) {
                wx.hideLoading(), 1 != t.code ? o.request({
                    url: n.user.send_sms + "&phone=" + e.data.phone + "&key=" + e.data.imgCodeKey + "&captcha=" + e.data.imgcode,
                    method: "post",
                    data: {},
                    success: function(t) {
                        1 != t.code ? a.showToast("验证码获取失败", "none") : e.countDown();
                    }
                }) : a.showToast("该手机号已绑定账号", "none");
            }
        })) : a.showToast("请输入正确的电话号码格式", "none"));
    },
    countDown: function() {
        var e = this;
        e.data.gettingCode = !1, this.setData({
            gettingCode: !1
        });
        var t = 59, a = setInterval(function() {
            e.setData({
                sendtxt: t + "s"
            }), --t <= 0 && (a = clearInterval(a), e.setData({
                sendtxt: "获取验证码"
            }), e.data.gettingCode = !0, e.setData({
                gettingCode: !0
            }));
        }, 1e3);
    },
    getPhoneLogin: function(e) {
        var t = this;
        wx.showLoading({}), o.request({
            url: n.user.binding_phone,
            method: "post",
            data: {
                phone: t.data.phone,
                code: t.data.verificationcode,
                access_token: wx.getStorageSync("access_token")
            },
            success: function(e) {
                if (console.log(e), wx.hideLoading(), 0 == e.code) return a.showToast(e.msg, "none"), 
                t.data.gettingCode = !0, void t.setData({
                    gettingCode: !0
                });
                wx.showToast({
                    title: "绑定成功",
                    success: function(e) {
                        var a = wx.getStorageSync("user_info");
                        a.phone = t.data.phone, a.is_binding = 1, wx.setStorageSync("user_info", a), setTimeout(function() {
                            wx.reLaunch({
                                url: "/pages/map/driverServer/driverServer"
                            });
                        }, 1500);
                    }
                });
            }
        }), this.data.gettingCode;
    },
    onShareAppMessage: function() {
        var e = o.shareAppMessage().title, t = o.shareAppMessage().imageUrl, a = o.shareAppMessage().desc, n = o.shareAppMessage().path;
        return console.log(o.shareAppMessage()), {
            title: e,
            imageUrl: t,
            desc: a,
            path: n
        };
    }
});